import Vue from 'vue'
import App from './App.vue'
import router, { dynamicAddRoutes } from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import '@/assets/style.scss'
// import './assets/theme/index.css';
import { getUserMenus } from '@/utils/request'
import ObjectArray from '@/components/ObjectArray.vue'
import CustomIconSelect from '@/components/CustomIconSelect.vue'

Vue.use(ElementUI, { size: 'small'});
Vue.component(ObjectArray.name, ObjectArray)
Vue.component(CustomIconSelect.name, CustomIconSelect)

let menusData
router.beforeEach(async (to, from, next) => {
  if (!menusData) {
    menusData = await getUserMenus()
    const routerData = menusData.filter(i => i.componentPath).map(i => ({ ...i, parent: menusData.find(j => j.id === i.pid) }))
    dynamicAddRoutes(routerData);
    next(to.fullPath)
  }
  next()
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')


export function userMenusData() {
  return menusData
}